package com.rgp.servicedriveruser.service.impl;

import com.rgp.internalcommon.dto.PointsDto;
import com.rgp.internalcommon.dto.ResponseResult;
import com.rgp.internalcommon.dto.TrackPointsDto;
import com.rgp.servicedriveruser.feign.ServiceMapClient;
import com.rgp.servicedriveruser.mapper.CarMapper;
import com.rgp.servicedriveruser.pojo.Car;
import com.rgp.servicedriveruser.service.DriverPointsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @author nhp
 * @version 1.0
 * @description TODO
 * @date 2024-04-20 2:43
 */
@Service
public class DriverPointsServiceImpl implements DriverPointsService {

    @Autowired
    private CarMapper carMapper;

    @Autowired
    private ServiceMapClient serviceMapClient;

    @Override
    public ResponseResult upload(PointsDto pointsDto) {

        //1.根据车辆id查询对应的终端id[tid]与轨迹id[trid]
        String carId = pointsDto.getCarId();
        Car car = carMapper.selectById(Long.parseLong(carId));
        Long tid = car.getTid();
        Integer trid = car.getTrid();
        //2.调用service-map微服务，将车辆实时的经纬度进行上传
        TrackPointsDto trackPointsDto = new TrackPointsDto();
        trackPointsDto.setTid(tid);
        trackPointsDto.setTrid(trid);
        trackPointsDto.setPoints(pointsDto.getTrackPoints());
        return serviceMapClient.uploadTrackPoints(trackPointsDto);
    }
}